﻿using System;
using System.IO;

namespace SourcesUnPacker
{
    public class RoleData
    {

        public int roleId;
        public RoleFrame[] frames;
        public RoleAnimationData[] animations;


        public RoleAnimationData GetRoleAnimationData(EAnimationType eAnimationType,Dir dir)
        {
            //算法
            int dirNum = (int) dir;
            int animationTypeNum = (int) eAnimationType;
            var animId= dirNum+10*animationTypeNum;
            var anim=animations[animId];
            return anim;
        }
        public static RoleData read(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            var roleData = new RoleData();
            // 读取roleId
            roleData.roleId = reader.ReadInt32();
            // 读取frames数组的长度
            var framesCount = reader.ReadInt32();
            roleData.frames = new RoleFrame[framesCount];
            //打印一下
            for (int i = 0; i < framesCount; i++)
            {
                // Console.WriteLine("========================================================="+i);
                var frame= RoleFrame.read(reader);
                roleData.frames[i] = frame;
            }
            // 读取animations
            int animationsCount = reader.ReadInt32();
            //打印一下
            // Console.WriteLine("animationsCount:" + animationsCount);
            roleData.animations = new RoleAnimationData[animationsCount];
            for (int i = 0; i < animationsCount; i++)
            {
                var animation = RoleAnimationData.read(reader);
                roleData.animations[i] = animation;
            }
            return roleData;
        }
    }
}